// @ts-ignore
/* eslint-disable */
import { request } from 'umi';

/** 作品信息修改 作品信息修改 PUT /api/item */
export async function putItem(
  params: {
    // path
  },
  body: API.ModelsItemPut,
  options?: { [key: string]: any },
) {
  const { ...queryParams } = params;
  return request<API.ModelsItemResponse>('/api/item', {
    method: 'PUT',
    headers: {
      'Content-Type': 'application/json',
    },
    params: { ...queryParams },
    data: body,
    ...(options || {}),
  });
}

/** 作品创建 作品创建 POST /api/item */
export async function postItem(
  params: {
    // path
  },
  body: API.FormDataModelsItemPost,
  options?: { [key: string]: any },
) {
  const { ...queryParams } = params;
  const formData = new FormData();

  Object.keys(body).forEach((ele) => {
    const item = (body as any)[ele];

    if (item !== undefined && item !== null) {
      formData.append(ele, item);
    }
  });

  return request<API.ModelsItemResponse>('/api/item', {
    method: 'POST',
    params: { ...queryParams },
    data: formData,
    ...(options || {}),
  });
}

/** 作品信息获取 作品信息获取 GET /api/item/${param0} */
export async function getItem(
  params: {
    // path
    fileHash: string;
  },
  options?: { [key: string]: any },
) {
  const { fileHash: param0, ...queryParams } = params;
  return request<API.ModelsItemResponse>(`/api/item/${param0}`, {
    method: 'GET',
    params: { ...queryParams },
    ...(options || {}),
  });
}

/** 作品信息集合获取 作品信息集合获取 GET /api/items/ */
export async function getItems(
  params: {
    // query
    pageSize?: number;
    current?: number;
    creatorAddress?: string;
    ownerAddress?: string;
    approved?: string;
    status?: number;
    name?: string;
    category?: number;
    // path
  },
  options?: { [key: string]: any },
) {
  const { ...queryParams } = params;
  return request<API.ModelsItemsResponse>('/api/items/', {
    method: 'GET',
    params: {
      ...queryParams,
    },
    ...(options || {}),
  });
}
